{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from sklearn.metrics import roc_auc_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "lgb1_sub = pd.read_csv('prob/sub_lgb1.csv')\n",
    "xgb1_sub = pd.read_csv('prob/sub_xgb1.csv')\n",
    "lgb2_sub = pd.read_csv('prob/sub_lgb2.csv')\n",
    "xgb2_sub = pd.read_csv('prob/sub_xgb2.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "lgb1_oof = pd.read_csv('prob/oof_lgb1.csv')\n",
    "xgb1_oof = pd.read_csv('prob/oof_xgb1.csv')\n",
    "lgb2_oof = pd.read_csv('prob/oof_lgb2.csv')\n",
    "xgb2_oof = pd.read_csv('prob/oof_xgb2.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sub = lgb1_sub.copy()\n",
    "sub.rename({'prob': 'prob_lgb1'}, axis=1,inplace=True)\n",
    "sub['prob_xgb1'] = xgb1_sub['prob'].values.tolist()\n",
    "sub['prob_lgb2'] = lgb2_sub['prob'].values.tolist()\n",
    "sub['prob_xgb2'] = xgb2_sub['prob'].values.tolist()\n",
    "\n",
    "sub.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "oof = lgb1_oof.copy()\n",
    "oof.rename({'prob': 'prob_lgb1'}, axis=1,inplace=True)\n",
    "oof['prob_xgb1'] = xgb1_oof['prob'].values.tolist()\n",
    "oof['prob_lgb2'] = lgb2_oof['prob'].values.tolist()\n",
    "oof['prob_xgb2'] = xgb2_oof['prob'].values.tolist()\n",
    "\n",
    "oof.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "auc1 = roc_auc_score(oof['label'], oof['prob_lgb1'])\n",
    "auc2 = roc_auc_score(oof['label'], oof['prob_xgb1'])\n",
    "auc3 = roc_auc_score(oof['label'], oof['prob_lgb2'])\n",
    "auc4 = roc_auc_score(oof['label'], oof['prob_xgb2'])\n",
    "\n",
    "auc1, auc2, auc3, auc4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "oof['prob'] = oof['prob_lgb1']**0.5 * oof['prob_xgb1'] ** 0.4 * oof['prob_lgb2'] ** 0.4 * oof['prob_xgb2'] ** 0.25\n",
    "auc = roc_auc_score(oof['label'], oof['prob'])\n",
    "auc"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sub['prob'] = sub['prob_lgb1']**0.5 * sub['prob_xgb1'] ** 0.4 * sub['prob_lgb2'] ** 0.4 * sub['prob_xgb2'] ** 0.25\n",
    "sub.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sub[['user', 'prob']].to_csv('sub/ronghe.csv', index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "conda_python3",
   "language": "python",
   "name": "conda_python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
